package cn.taoticket.controller;

import cn.taoticket.common.Dto;
import cn.taoticket.common.DtoUtil;
import cn.taoticket.common.EmptyUtils;
import cn.taoticket.common.MD5;
import cn.taoticket.pojo.TaoticketUser;
import cn.taoticket.service.TaoTicketUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/api")
public class TaoTicketUserController {
    @Autowired
    private TaoTicketUserService taoTicketUserService;
    /**账号密码登录
     * 该方法执行后如果成功根据文档要求返回两个对象，包括登录的用户信息和用户Token信息
     * 失败则返回错误信息即可
     */
    @RequestMapping(value = "/p/login",method = RequestMethod.POST)
    public Dto login(@RequestBody TaoticketUser taoticketUser) throws Exception {
        //将密码用MD5做加密转化
        taoticketUser.setPassword(MD5.getMd5(taoticketUser.getPassword(),32));
       Object[] result =  taoTicketUserService.login(taoticketUser);
        if (EmptyUtils.isEmpty(result)) {
            return DtoUtil.returnFail("登录失败","0000");
        }else {
            return DtoUtil.returnSuccess("登录成功",result);
        }
    }
}
